package com.gitee.wsl.data.state.statekeeper

import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.json.Json

internal val essentyJson: Json =
    Json {
        allowStructuredMapKeys = true
    }

//internal expect fun <T> T.serialize(strategy: SerializationStrategy<T>): ByteArray
//
//internal expect fun <T> ByteArray.deserialize(strategy: DeserializationStrategy<T>): T

internal fun <T> T.serialize(strategy: SerializationStrategy<T>): ByteArray =
    essentyJson.encodeToString(serializer = strategy, value = this).encodeToByteArray()

internal fun <T> ByteArray.deserialize(strategy: DeserializationStrategy<T>): T =
    essentyJson.decodeFromString(deserializer = strategy, string = decodeToString())
